/**
 * Created by duwei on 2018/12/1.
 */

var NewCoinShopPayWindow = Window.extend({
    _ccsFileName: res.NewCoinShopPayWindow_json,

    _onCCSLoadFinish: function () {
        View.prototype._onCCSLoadFinish.call(this);
        this._addCloseBtn();

    },
    refreshData: function (payType, cid, fangkaNum, price) {
        var self = this;
        cc.log(payType);
        cc.log(cid, fangkaNum, price);
        var wxPayType = 0;
        var ylPayType = 0;

        for (var i = 0; i < payType.length; i++) {
            for (var key in payType[i]) {
                if (payType[i][key] == '微信') {
                    wxPayType = key;
                    self._nodeList['wxPay'].setVisible(true);
                }
                else if (payType[i][key] == '银联') {
                    ylPayType = key;
                    self._nodeList['ylPay'].setVisible(true);
                }
            }
        }
        if (payType.length == 2) {
            self._nodeList['wxPay'].setPositionX(-120);
            self._nodeList['ylPay'].setPositionX(120);
        }
        TouchUtil.setOnclickListener(self._nodeList['wxPay'], function () {
            self._getFangKaOrder(wxPayType, cid, fangkaNum, price);

        });
        TouchUtil.setOnclickListener(self._nodeList['ylPay'], function () {
            self._getFangKaOrder(ylPayType, cid, fangkaNum, price);

        });

    },
    //获取房卡订单 之后 拉起url进行支付
    _getFangKaOrder: function (payType, commodityId, cnt, price) {
        // showLoading('获取订单中...');
        var payUrl = NewCoinShopCfg.NewCoinShopPayUrl;
        var openUrl =payUrl+'area='+app.area+'&buyerId='+gameData.uid+'&source='+NewCoinShopCfg.NewCoinShopSource+'&ciType=1'+'&price='+price+'&cnt='+cnt+'&commodityId='+commodityId+'&payType='+payType;

        cc.log('openUrl==='+openUrl);
        cc.sys.openURL(openUrl);

        // var paramObj = {
        //     "area": app.area, //地区
        //     "buyerId": gameData.uid, //玩家id
        //     "ciType": 1,  //商品类型  1房卡 2金币
        //     "source": NewCoinShopCfg.NewCoinShopSource, //渠道类型，公众号或者APP，代理后台
        //     "jsapi": 0, //是否是公众号
        //     "openId": '', //微信openid
        //     "payType": payType, //选择支付类型
        //     "commodityId": commodityId,//商品id
        //     "cnt": cnt, //房卡数量
        //     "price": price //当前页面金额
        // };
        // http.postFormData(payUrl, paramObj,
        //     function (response) {
        //         hideLoading();
        //         console.log('支付订单url');
        //         console.log(response['data']);
        //         // showMessageBox(openUrl);
        //         if (response['data']) {
        //             var openUrl = response['data'] + '&#http://';
        //             cc.sys.openURL(openUrl);
        //         }
        //         console.log(JSON.stringify(response));
        //     }, function (response) {
        //         showAlert('抱歉，系统繁忙！');
        //     }
        // );
    },


});